define(
	[
		'require',
		'./detail_nodedetail_errorcode_ctrl'
	],
	function(require){
		var Controller = require('./detail_nodedetail_errorcode_ctrl').extend({

			businessIdChange: Ember.observer("business.id", function(){
				this.set('keyWord', '');
			}),
			
			requireData: function(){
				var ctrl = this;

				var params = {
					appId: this.get("business.id"),
					tradeId: this.get("model.id"),
					keyWord: this.get("keyWord"),
					pageIndex: this.get("pageIndex"),
					startDate: +this.get("startDate"),
					endDate: +this.get("endDate")
				};

				if( isLocalDebugModel ){
					params = undefined;
				}

				return this.store.ajax("GET", "keytrades/errors", params)
				.then(function(response){
					var result = Ember.A(response.result);
					ctrl.set("pageIndex",response.meta.pageIndex);
					ctrl.set("totalRows",response.meta.total);
					ctrl.set("errorcodes",result);
					return response;
				});
			},

			requireErrorStack: function(error){
				var ctrl = this;

				var params = {
					appId: this.get("business.id"),
					tradeId: this.get("model.id"),
					uri: error.uri,
					errorCode: error.dimensionId,//errorCode做了转换
					startDate: +this.get("startDate"),
					endDate: +this.get("endDate")
				};

				if( isLocalDebugModel ){
					params = undefined;
				}

				this.store.ajax("GET", "keytrades/error/stack", params)
				.then(function(response){
					var errorStacks = Ember.A();
					Ember.A(response.result).forEach(function(item, i){
						errorStacks.push({
							_index: i+1,
							_isLoaded: false,
							id: item.errorId,
							_formattedTime:APM.util.formatDate(item.timestamp, "yyyy-MM-dd H:mm"),
							errorMessage:error.errorMessage
						});
					});
					ctrl.set("errorStacks", errorStacks);
					ctrl.set("curErrorStack", errorStacks[0]);
					return response;
				});
			},

			requireErrorStackDetail: function(error){
				var ctrl = this;
				var params = {
					appId: this.get("business.id"),
					tradeId: this.get("model.id")
				};

				if( isLocalDebugModel ){
					params = undefined;
				}

				this.store.ajax("GET", "keytrades/error/stack/"+(isLocalDebugModel?1:error.id), params)
				.then(function(response){
					var errorStack = response.result;
					errorStack._index = error._index;
					errorStack._isLoaded = true;
					errorStack._formattedTime = error._formattedTime;
					errorStack.errorMessage = error.errorMessage;
					Ember.A(errorStack.fields);
					ctrl.set("curErrorStack", errorStack);
					ctrl.get("errorStacks")[errorStack._index-1] = errorStack;
					return response;
				});
			}
		});

		APM.BusinessDetailTradeErrorcodeController = Controller;

		return Controller;
	}
);	